<?php 
	class CountorPageModel extends Model {
		public function __construct(){
			$this->open(Model::MYSQL);
			$this->calledClass(get_class($this));
		}
		public function pageFrequency($cid,$page){
			$record = $this->findAsObject(array("countor_id="=>$cid,"page="=>$page));
			if($record===null){
				$record = $this->save(array(
						"countor_id"=>$cid,
						"countor"=>1,
						"page"=>$page,
						"HTTP_USER_AGENT"=>$_SERVER["HTTP_USER_AGENT"],
						"created"=>date("Y-m-d H:i:s"),
						"modified"=>date("Y-m-d H:i:s"),
						));
			}else if(is_object($record)){
				$user_agent=explode("~",$record->HTTP_USER_AGENT);
				if(!Basic::arrayValueExist($_SERVER["HTTP_USER_AGENT"],$user_agent)){
					array_push($user_agent,$_SERVER["HTTP_USER_AGENT"]);
				}
				$user_agent=implode("~",$user_agent);
				$record=$this->update(array("HTTP_USER_AGENT"=>$user_agent,"countor"=>($record->countor+1),"modified"=>date("Y-m-d H:i:s")),array("id="=>$record->id));
			}
			return $record;
		}
	}